/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Entities;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 *
 * @author tofy
   Función: Permite acceder a la tabla cuentas de la bd Gatos por medio de persistencia añadimos mas cambios
 */
@Entity
@Table(name = "Cuentas", catalog = "Gastos", schema = "")
@NamedQueries({
    @NamedQuery(name = "Cuentas.findAll", query = "SELECT c FROM Cuentas c"),
    @NamedQuery(name = "Cuentas.findByCtaID", query = "SELECT c FROM Cuentas c WHERE c.ctaID = :ctaID"),
    @NamedQuery(name = "Cuentas.findByNombre", query = "SELECT c FROM Cuentas c WHERE c.nombre = :nombre"),
    @NamedQuery(name = "Cuentas.findBySaldo", query = "SELECT c FROM Cuentas c WHERE c.saldo = :saldo")})

    public class Cuentas implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "CtaID", nullable = false)
    private Long ctaID;
    @Column(name = "Nombre", length = 40)
    private String nombre;
    @Column(name = "Saldo", precision = 2)
    private Double saldo;
    @JoinColumn(name = "UsuarioID_fk", referencedColumnName = "UsuarioID")
    @ManyToOne
    private Usuarios usuarioIDfk;
    @OneToMany(mappedBy = "ctaIDfk")
    private Collection<Diario> diarioCollection;

    public Cuentas() {
    }

    public Cuentas(Long ctaID) {
        this.ctaID = ctaID;
    }

    public Long getCtaID() {
        return ctaID;
    }

    public void setCtaID(Long ctaID) {
        this.ctaID = ctaID;
    }

    public String getNombre() {
        return nombre;
    }

    public void setNombre(String nombre) {
        this.nombre = nombre;
    }

    public Double getSaldo() {
        return saldo;
    }

    public void setSaldo(Double saldo) {
        this.saldo = saldo;
    }

    public Usuarios getUsuarioIDfk() {
        return usuarioIDfk;
    }

    public void setUsuarioIDfk(Usuarios usuarioIDfk) {
        this.usuarioIDfk = usuarioIDfk;
    }

    public Collection<Diario> getDiarioCollection() {
        return diarioCollection;
    }

    public void setDiarioCollection(Collection<Diario> diarioCollection) {
        this.diarioCollection = diarioCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (ctaID != null ? ctaID.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Cuentas)) {
            return false;
        }
        Cuentas other = (Cuentas) object;
        if ((this.ctaID == null && other.ctaID != null) || (this.ctaID != null && !this.ctaID.equals(other.ctaID))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        //return "Entities.Cuentas[ctaID=" + ctaID + "]";
        return  nombre;
    }

}
